package com.learn.training.multithread.chapter7.demo2;

public class Task implements Runnable {

    private final String name;
    public Task(String name) {
        this.name = name;
    }


    @Override
    public void run() {
        try {
            if (name.contains("2")) {
                System.out.println("start " + name + "  :  " + Thread.currentThread().getName() + "  :  " + System.currentTimeMillis());
                // 在FixedRate模式下，假设每3秒触发，如果某次任务执行时间超过3秒，后续任务会不会并发执行？--会
//                Thread.sleep(5000);
                // 如果任务抛出了异常，后续任务是否继续执行？--会
                throw new RuntimeException("task2 exception");
            }else{
                System.out.println("start " + name + "  :  " + Thread.currentThread().getName() + "  :  " + System.currentTimeMillis());
                Thread.sleep(1000);
                System.out.println("end " + name + "  :  " + Thread.currentThread().getName() + "  :  " + System.currentTimeMillis());
            }
        } catch (InterruptedException e) {
        }
        System.out.println("end " + name);

    }
}
